import requests
import json

GOOGLE_TR_CODE = ["ja","ko","ar","th","ru","id","de","vi","el","hu","hi","id","it","fr","es","nl","pl","pt","ro","ru","ar","zh-TW","ko","sv","th","tr","vi"]


print('开始。。。。')
lang_count = 0

while lang_count < 2:
    with open("en.json",'r') as load_f:
        json_dict = json.load(load_f)
        json_keylist = list(json_dict.keys())
        #print(load_dict)
        

        counter = 0
        while counter < len(json_keylist):
            print("\n--------------"+GOOGLE_TR_CODE[lang_count]+"-----------------")
            print(json_dict[json_keylist[counter]])
            response = requests.get('https://translation.googleapis.com/language/translate/v2', params={'key': 'AIzaSyBtiAkwH7g3kr12aSdzCagOgzozD0N9G_A', 'source': 'en', 'target': GOOGLE_TR_CODE[lang_count], 'q': json_dict[json_keylist[counter]]})

            json_str = json.dumps(response.json())
            googleapi_return = json.loads(json_str)
            #print(json_str)
            tr_str = googleapi_return['data']['translations'][0]['translatedText']

            json_dict[json_keylist[counter]] = tr_str.replace('&#39;','‘').capitalize()
            print(tr_str)
            print("-------------------------------\n")
            counter += 1
    with open(""+GOOGLE_TR_CODE[lang_count]+".json","w+") as dump_f:
        json.dump(json_dict,dump_f,ensure_ascii=False,indent=2)

    lang_count += 1
    print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')

